package cn.crex1.xiaomi.core.orm.mapper;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.crex1.xiaomi.core.orm.datasource.JdbcDataSource;

public class MapperRegistry {
	
	private Map<String, MapperFactory> mapperMap=new HashMap<>();
	
	private MapperFactory mapperFactory;
	
	
	public MapperRegistry() {
		mapperFactory=new MapperFactory();
	}


	public <T> T getMapper(JdbcDataSource dataSource,Class<?> clazz,Object... args) {
		MapperFactory mapperFactory2 = mapperMap.get(clazz.getSimpleName());
		if (mapperFactory2!=null) {
			try {
				return mapperFactory2.newinstance(dataSource, clazz, args);
			} catch (NoSuchFieldException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}else {
			mapperMap.put(clazz.getSimpleName(), mapperFactory);
			try {
				return mapperFactory.newinstance(dataSource, clazz, args);
			} catch (NoSuchFieldException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return null;
	}
	
}
